home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
-
- #include "wlib.h"
- #include "winop.h"
-
- /*
- proto -s popup.c > temp
- */
- static int PopUpExec( WindowID, EventInfo* );
-
- static char **PopUpItem ;
- static int PopUpItems ;
- static int PopUpFont ;
- static int ReturnCode ;
-
- static int PopUpExec( wp, info )
- WindowID wp ;
- EventInfo *info ;
- {
- if( info->option == EventRedraw ){
- int i, h, v ;
- DrawBuf dbuf[44], *dp= dbuf;
- WindowGetViewSize( wp, &h, &v );
- DrawSetClear( dp++, 1 );
- for( i = 0 ; i < PopUpItems ; ++i )
- DrawSetSymbol( dp++, 4, PopUpFont*i, PopUpItem[i], AttrDefault, PopUpFont );
- i= PopUpFont * ReturnCode ;
- DrawSetLine( dp++, 0, i, h-1, i+PopUpFont-1, 1+OptionXor, OptionFill );
- WindowDraw( wp, dbuf, dp-dbuf );
- }
- return TRUE;
- }
-
- static
- X_strlen( ptr )
- char *ptr;
- {
- int i= 0;
- for(; *ptr++ ; i++ );
- return i;
- }
-
- int PopUpMenu( x, y, item, items, font )
- int x, y ;
- char **item ;
- int items, font ;
- {
- int h, sx, sy;
- WindowID wp;
- EventInfo info;
-
- PopUpItem= item;
- PopUpItems= items;
- PopUpFont= font;
-
- {
- int n, i;
- for( i= h= 0 ; i < items ; i++ ){
- if( (n= X_strlen( *item++ )) >= h )
- h= n;
- }
- h= h*font/2+8;
- }
-
- wp= WindowSimpleOpen( x, y, h, items*font, NULL, PopUpExec );
- WindowGetScreenPosition( wp, &sx, &sy );
-
- WindowGetEventInfo( &info );
- ReturnCode= (info.y-sy) / font;
- if( info.y-sy < 0 || ReturnCode >= items )
- ReturnCode= -2;
-
- WindowRedraw( wp );
- info.LeftStat= info.RightStat= TRUE;
-
- do{
- if( WindowGetEventInfo( &info ) ){
- int new= (info.y-= sy) / font;
- if( info.y < 0 || new >= PopUpItems )
- new= -2;
- if( ReturnCode != new ){
- DrawBuf dbuf[2] ;
- DrawSetLine( dbuf, 0, PopUpFont*new, h-1,
- PopUpFont*new+PopUpFont-1, 1|OptionXor, OptionFill );
- DrawSetLine( dbuf+1, 0, PopUpFont*ReturnCode, h-1,
- PopUpFont*ReturnCode+PopUpFont-1, 1|OptionXor, OptionFill);
- WindowDraw( wp, dbuf, 2 );
- ReturnCode= new;
- }
- }
- }while( info.LeftStat || info.RightStat );
- WindowClose( wp );
- return ReturnCode;
- }
-
-